/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package test.suite.dxframework.patterns.component
{

import org.flexunit.Assert;
import org.fluint.uiImpersonation.UIImpersonator;
import org.teotigraphix.dx.core.ToolKitGlobals;
import org.teotigraphix.dx.interfaces.IBehaviorLayer;
import org.teotigraphix.dx.interfaces.IComponentBehaviorCore;
import org.teotigraphix.dx.interfaces.IComponentModelCore;
import org.teotigraphix.dx.interfaces.IModelLayer;
import org.teotigraphix.dx.interfaces.ISkinLayer;
import org.teotigraphix.dx.interfaces.IToolKitFactory;
import org.teotigraphix.dx.patterns.component.ToolKitFactory;

import test.suite.dxframework.support.behavior.TestComponentBehaviorCore;
import test.suite.dxframework.support.component.TestComponent;
import test.suite.dxframework.support.component.factory.TestMXMLToolKitFactory;
import test.suite.dxframework.support.component.factory.TestToolKitComponentFactory;
import test.suite.dxframework.support.layer.TestComponentBehaviorLayer;
import test.suite.dxframework.support.layer.TestComponentModelLayer;
import test.suite.dxframework.support.layer.TestComponentSkinLayer;
import test.suite.dxframework.support.model.TestComponentModelCore;

/**
 * Tests the <code>ToolKitFactory</code> properties API.
 * 
 * @author Michael Schmalle
 * @copyright Teoti Graphix, LLC
 * @date 07-21-09
 */
public class TC_ToolKitFactory
{
	//--------------------------------------------------------------------------
	//
	//  Private :: Variables
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @private
	 */
	private var component:TestComponent;
	
	/**
	 * @private
	 */
	private var factory:ToolKitFactory;
	
	private var cfactory:TestToolKitComponentFactory
	private var mxmlfactory:TestMXMLToolKitFactory
	
	//--------------------------------------------------------------------------
	//
	//  Overridden Protected :: Methods
	//
	//--------------------------------------------------------------------------
	
	[Before(ui)]
	/**
	 * @private
	 */
	public function setUp():void
	{
		ToolKitGlobals.VALIDATION_EVENTS_ENABLED = true;
		component = new TestComponent();
		factory = new ToolKitFactory();
		cfactory = new TestToolKitComponentFactory();
		mxmlfactory = new TestMXMLToolKitFactory();
		
		component.toolKitFactory = mxmlfactory;
		UIImpersonator.addChild( component );		
	}
	
	[After]
	/**
	 * @private
	 */
	public function tearDown():void
	{
		ToolKitGlobals.VALIDATION_EVENTS_ENABLED = false;
		
		UIImpersonator.removeChild( component );
		component = null;
		factory = null;
		cfactory = null;
		mxmlfactory = null;
	}
	
	[Test]
	/**
	 * Tests the <code>implements</code>.
	 */
	public function test_ToolKitFactory_implements():void
	{
		Assert.assertTrue( "!IToolKitFactory", (factory is IToolKitFactory) );
		Assert.assertTrue( "!IToolKitFactory", (cfactory is IToolKitFactory) );
		Assert.assertTrue( "!IToolKitFactory", (mxmlfactory is IToolKitFactory) );
	}
	
	[Test]
	/**
	 * Tests the <code>extends</code>.
	 */
	public function test_ToolKitFactory_extends():void
	{
		Assert.assertTrue( "!ToolKitFactory", (factory is ToolKitFactory) );
		Assert.assertTrue( "!ToolKitFactory", (cfactory is ToolKitFactory) );
		Assert.assertTrue( "!ToolKitFactory", (mxmlfactory is ToolKitFactory) );
	}	
	
	[Test]
	/**
	 * Tests the <code>cores</code> for null defaults.
	 */
	public function test_cores():void
	{
		Assert.assertNull( "factory.coreBehavior not null", factory.coreBehavior  );
		Assert.assertNull( "factory.coreModel not null", factory.coreModel  );
	}	
	
	[Test]
	/**
	 * Tests the <code>layers</code> for null defaults.
	 */
	public function test_layers():void
	{
		Assert.assertNull( "factory.behaviorLayer not null", factory.behaviorLayer  );
		Assert.assertNull( "factory.modelLayer not null", factory.modelLayer  );
		Assert.assertNull( "factory.skinLayer not null", factory.skinLayer  );
	}
	
	[Test]
	/**
	 * Tests the factory methods for defaults.
	 */
	public function test_factory_methods():void
	{
		var bl:IBehaviorLayer = factory.createBehaviorLayer();
		var cb:IComponentBehaviorCore = factory.createCoreBehavior();
		var cs:IComponentModelCore = factory.createCoreModel();
		var sl:IModelLayer = factory.createModelLayer();
		var skl:ISkinLayer = factory.createSkinLayer();
		
		Assert.assertNotNull( "IBehaviorLayer null", bl );
		Assert.assertNotNull( "IComponentBehaviorCore null", cb );
		Assert.assertNotNull( "IComponentModelCore null", cs );
		Assert.assertNotNull( "IServiceLayer null", sl );
		Assert.assertNotNull( "ISkinLayer null", skl );
		
		Assert.assertTrue( "behaviorLayer not IBehaviorLayer", (bl is IBehaviorLayer) );
		Assert.assertTrue( "coreBehavior not IComponentBehaviorCore", (cb is IComponentBehaviorCore) );
		Assert.assertTrue( "coreService not IComponentModelCore", (cs is IComponentModelCore) );
		Assert.assertTrue( "modelLayer not IModelLayer", (sl is IModelLayer) );
		Assert.assertTrue( "skinLayer not ISkinLayer", (skl is ISkinLayer) );
	}
	
	[Test]
	/**
	 * Tests the cfactory methods for defaults.
	 */
	public function test_actionscript_override_factory_methods():void
	{
		var bl:IBehaviorLayer = cfactory.createBehaviorLayer();
		var cb:IComponentBehaviorCore = cfactory.createCoreBehavior();
		var cs:IComponentModelCore = cfactory.createCoreModel();
		var sl:IModelLayer = cfactory.createModelLayer();
		var skl:ISkinLayer = cfactory.createSkinLayer();
		
		Assert.assertNotNull( "IBehaviorLayer null", bl );
		Assert.assertNotNull( "ICoreComponentBehavior null", cb );
		Assert.assertNotNull( "ICoreComponentService null", cs );
		Assert.assertNotNull( "IServiceLayer null", sl );
		Assert.assertNotNull( "ISkinLayer null", skl );
		
		Assert.assertTrue( "behaviorLayer not TestComponentBehaviorLayer", (bl is TestComponentBehaviorLayer) );
		Assert.assertTrue( "coreBehavior not TestComponentBehaviorCore", (cb is TestComponentBehaviorCore) );
		Assert.assertTrue( "coreService not TestComponentModelCore", (cs is TestComponentModelCore) );
		Assert.assertTrue( "modelLayer not TestComponentModelLayer", (sl is TestComponentModelLayer) );
		Assert.assertTrue( "skinLayer not TestComponentSkinLayer", (skl is TestComponentSkinLayer) );
	}
	
	[Test]
	/**
	 * Tests the mxmlfactory methods for defaults.
	 */
	public function test_mxml_override_factory_properties():void
	{
		var bl:IBehaviorLayer = mxmlfactory.createBehaviorLayer();
		var cb:IComponentBehaviorCore = mxmlfactory.createCoreBehavior();
		var cs:IComponentModelCore = mxmlfactory.createCoreModel();
		var sl:IModelLayer = mxmlfactory.createModelLayer();
		var skl:ISkinLayer = mxmlfactory.createSkinLayer();
		
		Assert.assertNotNull( "IBehaviorLayer null", bl );
		Assert.assertNotNull( "ICoreComponentBehavior null", cb );
		Assert.assertNotNull( "ICoreComponentService null", cs );
		Assert.assertNotNull( "IServiceLayer null", sl );
		Assert.assertNotNull( "ISkinLayer null", skl );
		
		Assert.assertTrue( "behaviorLayer not TestComponentBehaviorLayer", (bl is TestComponentBehaviorLayer) );
		Assert.assertTrue( "coreBehavior not TestComponentBehaviorCore", (cb is TestComponentBehaviorCore) );
		Assert.assertTrue( "coreService not TestComponentModelCore", (cs is TestComponentModelCore) );
		Assert.assertTrue( "modelLayer not TestComponentModelLayer", (sl is TestComponentModelLayer) );
		Assert.assertTrue( "skinLayer not TestComponentSkinLayer", (skl is TestComponentSkinLayer) );
	}
	
	[Test]
	/**
	 * Tests the mxmlfactory methods for defaults.
	 */
	public function test_set_toolKitFactory_from_mxml_factory():void
	{
		Assert.assertTrue( "component.toolKitFactory not TestMXMLToolKitFactory", 
			(component.toolKitFactory is TestMXMLToolKitFactory) );
		 
		Assert.assertTrue( "behaviorLayer not TestComponentBehaviorLayer", 
			(component.behaviorLayer is TestComponentBehaviorLayer) );
		Assert.assertTrue( "coreBehavior not TestComponentBehaviorCore", 
			(component.coreBehavior is TestComponentBehaviorCore) );
		Assert.assertTrue( "coreModel not TestComponentModelCore", 
			(component.coreModel is TestComponentModelCore) );
		Assert.assertTrue( "modelLayer not TestComponentModelLayer", 
			(component.modelLayer is TestComponentModelLayer) );
		Assert.assertTrue( "skinLayer not TestComponentSkinLayer", 
			(component.skinLayer is TestComponentSkinLayer) );
		
	}	
	
	[Test]
	/**
	 * Tests the mxmlfactory methods for defaults.
	 */
	public function _test_set_toolKitFactory_after_addChild():void
	{
		// TODO IMPL
	}

}
}